/////////////////////////////////////////////////////////////////////////////////////
// Parameters

// Higher values = higher resolution
 $fn=60;
 
/*[ Hose adapter part ]*/
// Maximum exterior diameter of barbed hose adapter [millimeters]. This is the max. diameter the hose is supposed to fit over
hoseAdExtDia = 10;
// Length of the barbed hose adapter [millimeters]
hoseAdLen = 20;
// Wall thickness of the barbed hose adapter [millimeters]
hoseAdWall = 2;
// Number of barbs
barbeCount = 4;
// Diameter decrease of barbes [millimeters]
barbeDiaDecr = 1;

/*[ Pipe adapter part ]*/
// Diameter of the pipe the adapter should fit over [millimeters]
pipeDia = 18;
// Length of adapter part that goes over the pipe [millimeters]
pipeAdLen=20;
// Wall thickness of the pipe adapter part [millimeters]
pipeAdWall = 4;

/*[ Transition between pipe and hose adapter parts ]*/
// Length of the transition part [millimeters]
transitionLen=15;

/////////////////////////////////////////////////////////////////////////////////////
// Main
color("cyan")
union()
{
  translate([0,0,transitionLen+pipeAdLen])
    makeHoseAdapter();
  translate([0,0,pipeAdLen])
    makeTransition();
  makePipeAdapter();
} 
printStats();
/////////////////////////////////////////////////////////////////////////////////////
//
module makeTransition() 
{
  difference()
  {
    cylinder(d1=pipeDia+2*pipeAdWall, d2=hoseAdExtDia, h=transitionLen+0.01);
    translate([0,0,-0.01])
    cylinder(d1=pipeDia-1, d2=hoseAdExtDia-2*hoseAdWall, h=transitionLen+0.03);
  }
}
/////////////////////////////////////////////////////////////////////////////////////
//
module makePipeAdapter() 
{
  difference()
  {
    cylinder(d=pipeDia+2*pipeAdWall, h=pipeAdLen+0.01);
    translate([0,0,-0.01])
    cylinder(d1=pipeDia+1, d2=pipeDia-1,  h=pipeAdLen+0.03);
  }
}
/////////////////////////////////////////////////////////////////////////////////////
//
module makeHoseAdapter() 
{
  stepZ = hoseAdLen/barbeCount;
  difference()
  {
    for (step = [0 : barbeCount-1]) 
    {
      translate([0, 0, step * stepZ])
        cylinder(d1=hoseAdExtDia, d2=hoseAdExtDia-barbeDiaDecr, h=stepZ);
    }
    translate([0, 0, -1])
      cylinder(d = hoseAdExtDia-2*hoseAdWall, h=hoseAdLen+2);
  }
}
//////////////////////////////////////////////////////////////////////
//
module printStats()
{
    strStats=str("\n############################ STATISTICS ############################\n",
    "Measurements in millimeter [mm]\n\n",
    "\Barbed hose adapter:\n",
    "\t Max. outer diameter:\t", hoseAdExtDia, "\n",
    "\t Min. outer diameter:\t", hoseAdExtDia-barbeDiaDecr, "\n",
    "\t Inner diameter:\t", hoseAdExtDia-2*hoseAdWall, "\n",
    "\n############################ STATISTICS ############################\n"
   );
    
    echo(strStats );
}